package com.kitty.ibatis;

import java.io.*;
import java.sql.SQLException;
import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;     
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class IbatisBaseDao {
	private SqlMapClient sqlMapClient;
	public IbatisBaseDao() throws IOException {
		this.init();
	}
	
	private void init() throws IOException {
		
		//File f = new File("D:/workspace/thursday20120824/javaprojArtId/src/main/resources/sqlMapConfig.xml");
		//System.out.println(f.length());
		
		//ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		
		Resource resource = new ClassPathResource("sqlMapConfig.xml");
		
		//System.out.println(context.getBean("sqlMapClient"));
		
		//Reader reader = Resources.getResourceAsReader("D:/workspace/thursday20120824/javaprojArtId/src/main/resources/sqlMapConfig.xml");
		Reader reader = new InputStreamReader(new FileInputStream(resource.getFile()));
		sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
		 
		 
	}
	
	public void query() {
		try {
			List result = this.sqlMapClient.queryForList("markCouponCode.selectMarkCouponCodes");
			//Object result = this.sqlMapClient.queryForObject("markCouponCode.tt");
			System.out.print(result.get(0));
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) throws IOException {
		IbatisBaseDao dao = new IbatisBaseDao();
		dao.query();
	}
	
}
